#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int compare(const void* e1, const void* e2)
{
	return *(int*)e1 - *(int*)e2;
}
int print(int* p, int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", p[i]);
	}
	printf("\n");
}
void swap(char* num1, char* num2, size_t width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char tmp = 0;
		tmp = *num1;
		*num1 = *num2;
		*num2 = tmp;
		num1++;
		num2++;
	}
}

void bubble_sort(void* base, size_t sz, size_t width, int(*compare)(const void* e1, const void* e2))
{
	int i = 0;
	for (i = 0; i < sz-1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (compare((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
			{
				swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}

int main()
{
	int arr[10] = { 4,8,7,9,1,5,0,3,2,6 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	print(arr, sz);

	bubble_sort(arr, sz, sizeof(arr[0]), compare);
	print(arr, sz);

	return 0;
}